package motor;

import utils.Vector2d;

public abstract class ModuleMobile
{
	private float v = 2;
	
	protected Vector2d	vtemp = new Vector2d(-1,-1);
	private Vector2d pos = new Vector2d(-1,-1);
	
	protected Unite mere;
	
	
	public ModuleMobile( Unite mere )
	{
		this.pos = mere.getPos();
		this.mere = mere;
	}
	
	public Vector2d getPos()
	{
		return pos;
	}

	public float getV()
	{
		return v;
	}

	public void setV(float v)
	{
		this.v = v;
	}

	public Vector2d getVtemp()
	{
		return vtemp;
	}

	public void setVtemp(Vector2d vtemp)
	{
		this.vtemp = vtemp;
	}

	public final void move(Motor m)
	{
		Vector2d newd = new Vector2d(pos.x + vtemp.x , pos.y + vtemp.y );

		if( m.s.cansee( pos, newd) == null && m.collision( mere ) )
		{
			float val = (float) Math.sqrt(Math.pow(vtemp.x, 2 ) + Math.pow(vtemp.y, 2 ));
			
			if( val != 0 )
			{
				vtemp.x *= v/val;
				vtemp.y *= v/val;
				
				pos.x += vtemp.x;
				pos.y += vtemp.y;
				//System.out.println("Avance !!!!!");
			}
		}
	}
}
